import pylab as pl
import numpy as np
from scipy import integrate
from scipy.integrate import odeint
import matplotlib.pyplot as plt


# %fig=洛伦茨吸引子：微小的初值差别也会显著地影响运动轨迹 

def lorenz(w, t, b1, b2, c1, c2, d1, d2, e1, e2, n1, n2):
    x, y = w.tolist()

    return b1 * x * (1 - x / n1 + (c1 * n2 / y) - d1 * y / n2 - e1 * (x + y) * t), b2 * y * (
                1 - y / n2 + (c2 * n1 / x) - d2 * x / n1 - e2 * (x + y) * t)


t = np.arange(0, 100, 0.02)  # 创建时间点 
# 调用ode对lorenz进行求解, 用两个不同的初始值 
p = np.array([0.1, 0.2, 0.03, 0.02, 3, 2, 0.1, 0.2, 100, 250])
b1, b2, c1, c2, d1, d2, e1, e2, n1, n2 = p
track1 = odeint(lorenz, (0.0, 1.00), t, args=(b1, b2, c1, c2, d1, d2, e1, e2, n1, n2))  # ❷
plt.plot(track1[:, 0], track1[:, 1], lw=1)
plt.show()